package com.zmn.oms.common.enums;

import com.zmn.common.utils.date.DateUtil;
import lombok.Getter;

import java.util.Date;
import java.util.Objects;


/**
 * 类描述: 服务商改派时间枚举类
 *
 * @author liudi
 * @since: 2022/8/31 18:32
 */
@Getter
public enum SpRedistributeDateEnum {

	/**
	 * 前七天
	 */
	SEVEN_DAYS_BEFORE(1, TimeType.SEVEN_DAYS_BEFORE, TimeType.YESTERDAY),
	/**
	 * 昨天
	 */
	YESTERDAY(2, TimeType.YESTERDAY, TimeType.YESTERDAY),
	/**
	 * 今天
	 */
	TODAY(3, TimeType.TODAY, TimeType.TODAY),
	;

	/**
	 * 开始时间
	 */
	Date startTime;

	/**
	 * 结束时间
	 */
	Date endTime;

	/**
	 * 每个枚举项的唯一标识
	 */
	Integer code;

	SpRedistributeDateEnum(Integer code, TimeType startTimeType, TimeType endTimeType) {
		this.code = code;
		this.startTime = DateUtil.getDateStart(startTimeType.getDate());
		this.endTime = DateUtil.getDateEnd(endTimeType.getDate());
	}

	public static SpRedistributeDateEnum getEnumByCode(Integer code) {
		for (SpRedistributeDateEnum spRedistributeDateEnum : SpRedistributeDateEnum.values()) {
			if (Objects.equals(spRedistributeDateEnum.getCode(), code)) {
				return spRedistributeDateEnum;
			}
		}
		return null;
	}

	/**
	 * 时间类型枚举
	 */
	private enum TimeType {
		SEVEN_DAYS_BEFORE {
			@Override
			public Date getDate() {
				return DateUtil.addDays(DateUtil.getNow(), -7);
			}
		},
		YESTERDAY {
			@Override
			public Date getDate() {
				return DateUtil.addDays(DateUtil.getNow(), -1);
			}
		}, TODAY {
			@Override
			public Date getDate() {
				return DateUtil.getNow();
			}
		};

		public abstract Date getDate();
	}
}
